<template>
  <div class="caseManage">
    <el-tabs v-model="activeName" type="card" class="elTabs">
      <el-tab-pane name="first">
        <div slot="label" class="pageHeader">案件管理</div>
      </el-tab-pane>
    </el-tabs>

    <div class="container">
      <!-- 搜索查询 -->
      <div class="searchBar" v-show="showSearch">
        <div class="searchForm">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            label-width="80px"
          >
            <el-form-item label="来访形式" prop="online">
              <el-select v-model="queryParams.online" placeholder="请选择来访形式" clearable>
                <el-option
                  v-for="dict in dict.type.visiting_form"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="来访人姓名" prop="visitingName" label-width="90px">
              <el-input
                v-model="queryParams.visitingName"
                placeholder="请输入来访姓名"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="来访时间" prop="visitingTime">
              <el-date-picker
                clearable
                v-model="queryParams.selectVisitingTime"
                type="date"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptions"
                placeholder="请选择来访时间"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </div>
        <div class="searchButtons">
          <el-button class="searchButton" @click="handleQuery">搜索</el-button>
          <el-button class="resetButton" @click="resetQuery">重置</el-button>
        </div>
      </div>

      <!-- 新增、批量删除、导入、导出 -->
      <div
        class="addDeleteBar"
        v-if="
          checkPermi(['supervision:demands:add', 'supervision:demands:remove'])
        "
      >
        <el-button class="addButton" @click="handleAdd" v-hasPermi="['supervision:demands:add']">新增</el-button>
        <el-button
          @click="handleDelete"
          :class="!multiple ? 'deleteButton' : 'allDeleteButton'"
          :disabled="multiple"
          icon="el-icon-delete"
          v-hasPermi="['supervision:demands:remove']"
        >批量删除</el-button>
      </div>

      <!-- 表单选择清空 -->
      <div class="tableSelectArea">
        <div>
          <div class="iconInfo el-icon-info"></div>
          <span class="infoText">已选择</span>
          <span class="infoText infoActive" v-text="selectedNum"></span>
          <span class="infoText">项</span>
          <span class="infoButton" @click="clearSelect">清空</span>
        </div>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </div>
      <div class="table">
        <el-table
          v-loading="loading"
          class="tableArea"
          :data="demandsList"
          @selection-change="handleSelectionChange"
          ref="multipleTable"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="来访人姓名" align="center" prop="visitingName" />
          <el-table-column label="来访时间" align="center" prop="visitingTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.visitingTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="来访形式" align="center" prop="online">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.visiting_form" :value="scope.row.online" />
            </template>
          </el-table-column>
          <el-table-column label="来访案件" align="center" prop="caseName" :formatter="formatCaseValue" />
          <el-table-column
            label="来访诉求"
            align="center"
            prop="visitingDemand"
            :show-overflow-tooltip="true"
          />
          <el-table-column label="操作" align="left" width="180px" fixed="right">
            <template slot-scope="scope">
              <div class="tableButtonArea">
                <el-button type="text" class="operationButton" @click="handleDetail(scope.row)">详情</el-button>
                <el-button
                  type="text"
                  class="operationButton"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['supervision:demands:edit']"
                >修改</el-button>
                <el-button
                  type="text"
                  class="operationButton"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['supervision:demands:remove']"
                >删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <demands-manage-modal
        ref="demandsManageModal"
        :modalType.sync="modalType"
        :id="id"
        @fatherMethod="fatherMethod"
      ></demands-manage-modal>
      <demands-detail-modal :detailId.sync="detailId"></demands-detail-modal>
    </div>
  </div>
</template>

<script>
import {
  listDemands,
  getDemands,
  delDemands,
  addDemands,
  updateDemands,
} from "@/api/warning/demands/demands";
import { listCase } from "@/api/caseManage/case";
import { checkPermi, checkRole } from "@/utils/permission";
import { fatherMethod } from "@/utils/commonMethods";
import { MODALTYPE } from "@/utils/variable";

import demandsDetailModal from "./component/demandsDetailModal.vue";
import demandsManageModal from "./component/demandsManageModal.vue";

export default {
  name: "Demands",
  dicts: ["visiting_form"],
  components: { demandsDetailModal, demandsManageModal },
  data() {
    return {
      activeName: "first",
      selectedNum: 0,
      modalType: "",
      id: 0,
      //详情页Id
      detailId: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员诉求情况表格数据
      demandsList: [],
      // 案件选项
      caseOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openInfo: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        online: null,
        visitingName: null,
        selectVisitingTime: null,
      },
      // 表单参数
      form: {},
      formInfo: {},
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6
        },
      },
    };
  },
  computed: {},
  created() {
    this.getList();
    listCase().then((response) => {
      this.caseOptions = response.rows;
    });
  },
  methods: {
    fatherMethod,
    checkPermi,
    //清空列表选择
    clearSelect() {
      this.$refs.multipleTable.clearSelection();
    },
    /** 查询人员诉求情况列表 */
    getList() {
      this.loading = true;
      listDemands(this.queryParams).then((response) => {
        this.demandsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.detailId = row.id;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        online: "0",
        visitingName: null,
        visitingTime: null,
        caseName: null,
        visitingDemand: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelect: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 详情按钮操作 */
    handleInfo(row) {
      getDemands(row.id).then((response) => {
        this.formInfo = response.data;
        this.openInfo = true;
      });
    },
    /** 详情关闭按钮操作 */
    cancelInfo() {
      this.openInfo = false;
      this.formInfo = {};
      this.resetForm("formInfo");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.modalType = MODALTYPE["新增"];
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.modalType = MODALTYPE["修改"];
      this.id = row.id;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateDemands(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDemands(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      let num = this.selectedNum;
      if (row.id) {
        num = 1;
      }
      this.$modal
        .confirm("是否确认删除" + num + "条数据")
        .then(function () {
          return delDemands(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "supervision/demands/export",
        {
          ...this.queryParams,
        },
        `demands_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>


<style lang="scss" scoped>
@import "../../../assets/styles/variables.scss";
.caseManage {
  height: 100%;
  .tableFooter {
    text-align: right;
    justify-content: flex-end;
    // margin-top: 25px;
    margin-right: 35px;
    // width: 100%;
    ::v-deep .btn-prev {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .btn-next {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .el-pager li {
      background-color: #fff;
      border: 1px solid #d4d3d3;
      font-size: 12px;
      font-family: $font-family;
      font-weight: 400;
      color: #5a5b5d;
    }
  }
  .el-form-item__label {
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    font-size: $form-label-font-size;
    color: $form-label-color;
  }

  .el-input__inner {
    font-size: $form-content-font-size;
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    // color: #AEAFB0;
  }
}
.input {
  width: 150px;
}
::v-deep .el-tabs--card .el-tabs__header {
  background-color: #e4e7ed;
}
::v-deep.el-tabs--card .el-tabs__header .el-tabs__item {
  border-radius: 10px solid black;
  background-color: #fff;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #053ef6;
  line-height: 48px;
  margin-top: 0;
}
</style>
